package com.lk.springboot.dao;

import com.lk.springboot.pojo.ScoreRu;
import com.lk.springboot.vo.ScoreSummary;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * @author lk
 * @date 2020/1/12 0012 11:10
 */
@Mapper
public interface ScoreMapper {

    // 取出积分兑换中心概述
    @Select("select smallphoto.sp_id,url,rare,scru_id,score_num from score_ru,smallphoto where ru_type=#{ru_type} and score_ru.sp_id=smallphoto.sp_id")
    List<ScoreSummary> getScoreSummary(String ru_type);

    // 根据拼图id，查询出该拼图碎片的站点名称
    @Select("select s_name from sites,photo where sp_id=#{sp_id} and photo.p_id=sites.p_id")
    String getSName(String sp_id);

    //--------------------------------------------------------------------
    // 根据scru_id查询出 积分兑换详情（包括兑换中心 和 魔法市场）
    @Select("select * from score_ru where scru_id = #{scru_id}")
    ScoreRu getTheScoreRu(String scru_id);

    // 根据sp_id查出s_id
    @Select("select s_id from photo,sites where sp_id=#{sp_id} and photo.p_id = sites.p_id")
    String getSidBySp(String sp_id);

    // 减少用户积分
    @Update("update users set scores = scores - #{score_num} where u_id = #{u_id}")
    void reduceScore(@Param("u_id") String u_id, @Param("score_num") int score_num);

    // 返回用户当前积分
    @Select("select scores from users where u_id=#{u_id}")
    int getScore(String u_id);

    // 逛魔法市场一次，任务完成，进度置为1*
    @Update("update u_t_solve set speed = 1 where u_id=#{u_id} and t_id = 't10003' and speed < 999 ")
    void signMagic(String u_id);

    // 逛积分中心一次，任务完成，进度置为1*
    @Update("update u_t_solve set speed = 1 where u_id=#{u_id} and t_id = 't10002' and speed < 999 ")
    void signScore(String u_id);

    // 魔法市场 交易一次 ，记录加一
    @Update("update users set market_times = market_times + 1 where u_id = #{u_id} ")
    void alterMagicTimes(String u_id);

    // 获取魔法市场交易的次数
    @Select("select  market_times from users where u_id = #{u_id}")
    int getMarketNum(String u_id);

    // 获取用户是否买过魔法市场中的某一拼图
    @Select("select isbought from user_scoreru_magic where u_id=#{u_id} and scru_id = #{scru_id}")
    int getIsBought(@Param("u_id") String u_id, @Param("scru_id") String scru_id);

    // 标记魔法市场，相应的得拼图商品已经被用户买过了
    @Update("update user_scoreru_magic set isbought = 1 where u_id=#{u_id} and scru_id = #{scru_id}")
    void alterIsBought(@Param("u_id") String u_id, @Param("scru_id") String scru_id);

    //标记用户已经打开过游戏了
    @Update("update users set magic_status = 1 where u_id=#{u_id}")
    void  markMagicStatus(String u_id);

    //获取用户是否打开过游戏
    @Select("select magic_status from users where u_id=#{u_id}")
    int getUserMagicStatus(String u_id);

    //根据mapid查询站点的拼图p_id
    @Select("select p_id from sites where mapid=#{mapid}")
    String getPidByMapid(String mapid);
}
